/*
 * Copyright (c) 2008 Benoit Bouchez, Nicolas Giard
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.noocodecommit.wicket.stuff.jquery.plugin.effects.shake;

import com.noocodecommit.wicket.stuff.jquery.JQCore;
import com.noocodecommit.wicket.stuff.jquery.JQOptions;
import com.noocodecommit.wicket.stuff.jquery.exception.CannotApplyJQOptionException;
import com.noocodecommit.wicket.stuff.jquery.plugin.JQPlugin;
import com.noocodecommit.wicket.stuff.jquery.plugin.effects.IJQAnimation;
import com.noocodecommit.wicket.stuff.jquery.plugin.effects.JQAnimation;

/**
 * JQuery Effects Shake Animation
 * 
 * @author Benoit Bouchez
 * 
 */
public class JQShake implements IJQAnimation
{
	/** JQuery plugin */
	private JQShakePlugin plugin;
	/** Option set */
	private JQShakeOptions options = new JQShakeOptions();

	/**
	 * Constructor
	 */
	public JQShake()
	{
		super();
		if (JQCore.get().getPlugin(JQShakePlugin.DEFAULT_KEY) == null)
		{
			new JQShakePlugin();
		}
		this.plugin = (JQShakePlugin) JQCore.get().getPlugin(JQShakePlugin.DEFAULT_KEY);
	}

	/**
	 * Constructor
	 * 
	 * @param times
	 *            shake times
	 */
	public JQShake(int times)
	{
		this();
		this.options.setTimes(times);
	}

	/**
	 * Constructor
	 * 
	 * @param direction
	 *            shake direction
	 */
	public JQShake(String direction)
	{
		this();
		this.options.setDirection(direction);
	}

	/**
	 * Constructor
	 * 
	 * @param distance
	 *            shake distance
	 * @param direction
	 *            shake direction
	 * @param times
	 *            shake times
	 * @param speed
	 *            shake speed
	 */
	public JQShake(int distance, String direction, int times, int speed)
	{
		this();
		this.options.setDistance(distance);
		this.options.setDirection(direction);
		this.options.setTimes(times);
		this.options.setSpeed(speed);
	}

	public JQShakePlugin getPlugin()
	{
		return plugin;
	}

	public void setPlugin(JQPlugin plugin)
	{
		this.plugin = (JQShakePlugin) plugin;
	}

	public JQShakeOptions getOptions()
	{
		return options;
	}

	public void setOptions(JQOptions options)
	{
		if (options.getClass().equals(JQShakeOptions.class))
		{
			this.options = (JQShakeOptions) options;
		}
		else
		{
			throw new CannotApplyJQOptionException(JQShake.class, options.getClass(), JQShakeOptions.class);
		}
	}

	public String getAnimateOptions()
	{
		return options.getDefaultString();
	}

	public String getAnimateStyle()
	{
		return JQAnimation.ANIMATIONSTYLE_SHAKE;
	}

	public boolean isSupportedAnimationMode(String animationMode)
	{
		if (animationMode == JQAnimation.ANIMATIONMODE_EFFECT)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
